﻿using System.Collections;
using System.Text;
using Portal.Data.Entity;

namespace Portal.Data.Helper
{
    public class ExpressionHelper
    {
        public static string MakeInExpression(string propertyKey, object o, bool isCategory = true)
        {
            var sb = new StringBuilder();
            if (isCategory)
            {
                var po = (Category)o;
                sb.Append(" " + propertyKey + "=" + po.ID);
            }
            else
            {
                var po = (Module)o;
                sb.Append(" " + propertyKey + "=" + po.ID);
            }
            return sb.ToString();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="propertyKey"></param>
        /// <param name="objects"></param>
        /// <param name="isCategory">if FALSE is MODULE</param>
        /// <returns></returns>
        public static string MakeInExpression(string propertyKey, IList objects, bool isCategory = true)
        {
            var sb = new StringBuilder();
            if (objects != null && objects.Count > 0)
            {
                sb.Append(" " + propertyKey + " in (");
                if (isCategory)
                {
                    foreach (Category po in objects)
                    {
                        sb.Append(po.ID + ",");
                    }
                }
                else
                {
                    foreach (Module po in objects)
                    {
                        sb.Append(po.ID + ",");
                    }
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append(")");
            }
            else
            {
                sb.Append(" " + propertyKey + " in (0)");
            }

            return sb.ToString();
        }
    }
}
